package 面试2025.融360;

import java.util.ArrayDeque;
import java.util.Deque;

public class 大数相加 {
    public static void main(String[] args) {
        int num1 = 0, num2 = 0;
        String s = bigAdd(num1, num2);
        System.out.println(s);
    }
    private static String bigAdd(int num1, int num2){
        Deque<Integer> stack1 = new ArrayDeque<>();
        Deque<Integer> stack2 = new ArrayDeque<>();
        String s1 = String.valueOf(num1);
        String s2 = String.valueOf(num2);
        for(int i = 0;i < s1.length();i++){
            stack1.push(s1.charAt(i) - '0');
        }
        for(int i = 0;i < s2.length();i++){
            stack2.push(s2.charAt(i) - '0');
        }
        int bit = 0;
        StringBuilder sb = new StringBuilder();
        while(!stack1.isEmpty() || !stack2.isEmpty()){
            Integer a = stack1.isEmpty() ? 0 : stack1.pop();
            Integer b = stack2.isEmpty() ? 0 : stack2.pop();
            int sum = a + b + bit;
            sb.append(sum % 10);
            bit = sum / 10;
        }
        if(bit > 0){
            sb.append(bit);
        }
        return sb.reverse().toString();
    }
}
